<!-- 会员投诉管理 -->
<template>
  <div class="mod-config">
      <el-button-group style="margin-bottom: 10px;">
        <el-button icon="el-icon-search" type="primary" @click="searchHandle">查询</el-button>
        <el-button icon="el-icon-delete" type="primary" @click="searchReset">清空</el-button>
        <el-button v-if="permissions.eims_eimscustomerfeedback_add" icon="el-icon-plus" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-button-group>
      <el-form inline :model="dataForm">
        <el-form-item label="客户名称">
          <el-input v-model="dataForm.customerName"></el-input>
        </el-form-item>
        <el-form-item label="客户卡号">
          <el-input v-model="dataForm.customerCard"></el-input>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="dataForm.phone1"></el-input>
        </el-form-item>
        <el-form-item label="投诉单号">
          <el-input v-model="dataForm.complainNum"></el-input>
        </el-form-item>
        <el-form-item label="配镜单号">
          <el-input v-model="dataForm.billId"></el-input>
        </el-form-item>
        <el-form-item label="投诉类型">
          <el-select v-model="dataForm.complaintsType" placeholder="请选择投诉类型" clearable>
            <el-option  v-for="item in bizData.complaintsType" :key="item.value" :label="item.name" :value="item.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="投诉日期">
          <el-date-picker v-model="dataForm.createTimeMin" value-format="yyyy-MM-dd" clearable></el-date-picker>
          -
          <el-date-picker v-model="dataForm.createTimeMax" value-format="yyyy-MM-dd" clearable></el-date-picker>
        </el-form-item>
        <el-form-item label="处理状态">
          <el-select v-model="dataForm.status" placeholder="请选择处理状态" clearable>
            <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预处理时间">
          <el-date-picker v-model="dataForm.estimatedProcessingDateMin" value-format="yyyy-MM-dd" clearable></el-date-picker>
          -
          <el-date-picker v-model="dataForm.estimatedProcessingDateMax" value-format="yyyy-MM-dd" clearable></el-date-picker>
        </el-form-item>

        <el-form-item label="处理时间">
          <el-date-picker v-model="dataForm.dealDateMin" value-format="yyyy-MM-dd" clearable></el-date-picker>
          -
          <el-date-picker v-model="dataForm.dealDateMax" value-format="yyyy-MM-dd" clearable></el-date-picker>
        </el-form-item>
      </el-form>
      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading" :max-height="tableHeight">
          <el-table-column prop="complainNum" label="投诉单号" width="170"></el-table-column>
          <el-table-column prop="customerCard" label="会员卡号" width="130"></el-table-column>
          <el-table-column prop="customerName" label="会员姓名" width="80"></el-table-column>
          <el-table-column prop="complaintsType" label="投诉类型" width="80">
            <template slot-scope="scope">
              {{complaintsTypeChange(scope.row.complaintsType)}}
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="投诉时间" width="140"></el-table-column>
          <el-table-column prop="estimatedProcessingDate" label="预处理时间"></el-table-column>
          <el-table-column prop="dealDate" label="处理时间" width="140"></el-table-column>
          <el-table-column prop="status" label="处理状态" width="80">
            <template slot-scope="scope">
              <span v-if="scope.row.status == '1'">已处理</span><span v-else-if="scope.row.status == '2'">处理中</span><span v-else>未处理</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="180" fixed="right">
            <template slot-scope="scope">
              <el-button type="text" icon="el-icon-collection" @click="checkDetailHandle(scope.row.id)">详情</el-button>
              <el-button type="text" icon="el-icon-printer" v-if="scope.row.status == '1'" disabled>处理</el-button>
              <el-button type="text" icon="el-icon-printer" v-else @click="addOrUpdateHandle(scope.row.id)">处理</el-button>
              <el-button type="text" icon="el-icon-delete" v-if="scope.row.status" disabled >删除</el-button>
              <el-button type="text" icon="el-icon-delete" v-else @click="deleteHandle(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          background
          layout="total, sizes, prev, pager, next">
        </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
      <!-- 弹窗，详情 -->
      <detail-form v-if="detailVisible" ref="detailForm"></detail-form>
  </div>
</template>

<script>
  import {customerComplaintFetchList,customerComplaintDelObj} from '@/api/eims/customer-complaint.js'
  import TableForm from './form'
  import DetailForm from './detail'
  import {mapGetters} from 'vuex'
  import { filterParams } from "@/util/tools";
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        statusOptions: [ { value: 0, name: '未处理' },{ value: 2, name: '处理中' }, { value: 1, name: '已处理' }],
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false,
        detailVisible: false
      }
    },
    components: { TableForm, DetailForm },
    created () {
      this.getDataList()
    },
    computed: {
      ...mapGetters(['permissions','bizData']),
      tableHeight: function(){
       return window.innerHeight - 260
      }
    },
    methods: {
      searchHandle() {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        let params1 = {current: this.pageIndex,size: this.pageSize}
        let params2 = filterParams(this.dataForm)
        customerComplaintFetchList(Object.assign(params1,params2)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })

      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 搜索清空
      searchReset () {
        for(let key in this.dataForm){
        this.dataForm[key] = ''
        }
      },
     //刷新回调
      refreshChange() {
        this.getDataList(this.page);
      },
      // 查看投诉详情
      checkDetailHandle (id) {
        this.detailVisible = true
        this.$nextTick(() => { this.$refs.detailForm.init(id) })
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => { this.$refs.addOrUpdate.init(id) })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm('是否确认删除ID为' + id, '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'}).then(function () {
          return customerComplaintDelObj(id)
        }).then(response => {
          if(response.data.code == '0'){
            this.$message.success('删除成功')
            this.getDataList()
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      // 格式转化
      customerComplaintTypeFormatter (val) {
        switch (val.complaintsType) {
          case '01': return'商品质量'; break;
          case '02': return'验光'; break;
          case '03': return '销售'; break;
          case '04': return '加工质量'; break;
          case '05': return '检验'; break;
          case '06': return '送货'; break;
          case '07': return '服务态度'; break;
          case '08': return '订单失误'; break;
          case '09': return '调整校配'; break;
          case '10': return '时间延误'; break;
        }
      },
      complaintsTypeChange(type) {
        let obj = {}
        obj = this.bizData.complaintsType.find(item => {
          if(item.value == type){
            return item
          }
        })
        if(obj && obj.label){
          return obj.label
        }
      }
    }
  }
</script>
